package org.example.redis;

import com.alibaba.druid.pool.DruidDataSource;
import org.example.DruidUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author zhangjg
 * @desc 缓存去重
 * @date 2021/12/31 20:19
 **/
public class TestCache {

    private static final Logger log = LoggerFactory.getLogger(TestCache.class);

    public static void main(String[] args) throws Exception {

        Jedis jedis = new Jedis("127.0.0.1",6379);
        jedis.hset("key","k1","v1");
        String v = jedis.hget("key","k1");
        log.info("v={}",v);

        Connection connection = DruidUtil.getConnection();
        PreparedStatement pstm = connection.prepareStatement("SELECT portidx, name FROM test.port");
        ResultSet rs = pstm.executeQuery();
        while (rs.next()){
            log.info("idx={},name={}",rs.getLong(1),rs.getString(2));
        }
        DruidUtil.closeSQl(connection,pstm,rs);
    }

}
